package com.starblink.guangconfig.ui.part

import android.app.Activity
import com.starblink.android.basic.extension.navigationTo
import com.starblink.basic.route.RoutePage
import com.starblink.basic.util.CheckUtil
import com.starblink.guangconfig.databinding.ActivityGuangUpConfigBinding
import com.starblink.guangconfig.ui.GuangUpConfigVM
import com.starblink.android.common.utils.ScanUtil
import com.starblink.web.util.WebCacheUtil

object WebGuidePart {
    fun handleVM(context: Activity, m: GuangUpConfigVM, vb: ActivityGuangUpConfigBinding) {

        vb.webGuide.ivScanBtn.setOnClickListener {
            ScanUtil.startScan(context,false)
        }

        vb.webGuide.btnWebPre.setOnClickListener{
            var url:String=vb.webGuide.etWebGuide.text.toString()
            if(CheckUtil.isEmpty(url)){
                url="file:///android_asset/jsbridge.html?title=测试桥接"
            }
            //测试单个链接预加载
            WebCacheUtil.preLoadUrl(url)

            //测试
//            navigationTo(RoutePage.Brand.BRAND_ALL)
        }

        vb.webGuide.btnWebGuide.setOnClickListener {
            var url:String=vb.webGuide.etWebGuide.text.toString()
            if(CheckUtil.isEmpty(url)){
//                url="file:///android_asset/test.html?appTitle=测试"
                url="file:///android_asset/jsbridge.html?title=测试桥接"
            }

            navigationTo(RoutePage.Web.PAGE_GLOBAL_H5){
                withString(RoutePage.Web.ARG_URL, url)
                withString(RoutePage.Web.ARG_TITLE,"测试")
                withBoolean(RoutePage.Web.ARG_USECACHE,false)
                withBoolean(RoutePage.Web.ARG_STRICTMODE,true)
            }
        }
    }
}